package com.xbongbong.saas.enums;

import com.xbongbong.i18n.util.I18nMessageUtil;
import com.xbongbong.saas.enums.business.ProductEnum;
import com.xbongbong.saas.enums.business.StockProductEnum;
import lombok.Getter;

/**
 * 列表页options（下拉）的表头详细属性
 *
 * @author chaoxiong.lei
 * @Date 21:08 2019/3/11
 * @since v1.0
 * @return
 **/
@Getter
public enum SubOptionTableHeadEnum {
    // 库存查询
    PRODUCT_SPEC_NO(1, "productNo", "enum.subOptionTableHead.label.product_spec_no", ProductEnum.PRODUCT_NO.getSaasAttr()),
    PRODUCT_BARCODE(2, "barcode", "enum.subOptionTableHead.label.product_barcode", ProductEnum.BARCODE.getSaasAttr()),
    PRODUCT_SPECIFICATION(3, "specification", "enum.subOptionTableHead.label.product_specification", ProductEnum.SPECIFICATION.getSaasAttr()),
    PRODUCT_COST(4, "cost", "enum.subOptionTableHead.label.product_cost", ProductEnum.COST.getSaasAttr()),
    PRODUCT_STOCK(5, "stock", "enum.subOptionTableHead.label.product_stock", ProductEnum.STOCK.getSaasAttr()),
    PRODUCT_PRICE(6, "price", "enum.subOptionTableHead.label.product_price", ProductEnum.PRICE.getSaasAttr()),

    // 预警查询
    WARNING_WAREHOUSE(7, "warehouseName", "enum.subOptionTableHead.label.warning_warehouse", null),
    WARNING_TYPE(8, "warningType", "enum.subOptionTableHead.label.warning_type", null),
    WARNING_UPPER_LIMIT(9, "stockUpperLimit", "enum.subOptionTableHead.label.warning_upper_limit", null),
    WARNING_LOWER_LIMIT(10, "stockLowerLimit", "enum.subOptionTableHead.label.warning_lower_limit", null),

    // 保质期查询,
    GUARANTEE_STATUS(11, "guaranteeStatus", "enum.subOptionTableHead.label.guarantee_status", null),
    GUARANTEE_BATCH(12, "batch", "enum.subOptionTableHead.label.guarantee_batch", StockProductEnum.BATCH.getSaasAttr()),
    GUARANTEE_PRODUCE_DATE(13, "produceDate", "enum.subOptionTableHead.label.guarantee_produce_date", StockProductEnum.PRODUCE_DATE.getSaasAttr()),
    GUARANTEE_PERIOD(14, "guaranteePeriod", "enum.subOptionTableHead.label.guarantee_period", StockProductEnum.GUARANTEE_PERIOD.getSaasAttr()),
    PRODUCT_NUM(15, "num", "enum.subOptionTableHead.label.product_num", null),

    // 首页的预警查询
    WARNING_WAREHOUSE_UPPER(16, "warehouseUpper", "enum.subOptionTableHead.label.warning_warehouse_upper", null),
    WARNING_WAREHOUSE_LOWER(17, "warehouseLower", "enum.subOptionTableHead.label.warning_warehouse_lower", null),

    PRODUCT_COST_TOTAL(18, "costTotal", "enum.subOptionTableHead.label.product_cost_total", "costTotal"),
    PRODUCT_WAREHOUSE(19, "warehouse", "enum.subOptionTableHead.label.product_warehouse", ProductEnum.WAREHOUSE.getSaasAttr()),

    PRODUCT_IMAGE(20, "productImgs", "enum.subOptionTableHead.label.product_image", ProductEnum.PRODUCT_IMGS.getSaasAttr()),


    UNKNOW(XbbRefTypeEnum.UNKNOWN.getCode(), "", "", ""),
    ;
    private int code;
    private String prop;
    private String label;
    // 该属性用来与对应saas解释匹配，判断显隐，如果不受saas解释控制，则为null（始终显示），不是空串，防止判断的时候与自定义字段匹配到
    private String saasAttr;


    SubOptionTableHeadEnum(int code, String prop, String label, String saasAttr) {
        this.code = code;
        this.prop = prop;
        this.label = label;
        this.saasAttr = saasAttr;
    }

    public static SubOptionTableHeadEnum getByCode(Integer code) {
        for (SubOptionTableHeadEnum cacheCode : values()) {
            if (code.equals(cacheCode.getCode())) {
                return cacheCode;
            }
        }
        return null;
    }

    public String getLabel() {
        return I18nMessageUtil.getMessage(label);
    }
}
